﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display {
    import flash.events.*;
    import flash.display.*;
    import flash.geom.*;
    import Engine.Helpers.*;
    import Classes.*;
    import Engine.*;

    public class ResourceDialog extends SWFDialog {

        protected var m_resource:MapResource;
        protected var m_width:int;
        protected var m_height:int;
        protected var m_yOffset:int = 0;
        protected var m_xOffset:int = 0;
        protected var m_dialog:MovieClip;

        public function ResourceDialog(_arg1:MapResource, _arg2:Boolean=true){
            super(false);
            this.m_resource = _arg1;
        }
        override protected function onLoadComplete():void{
            this.m_dialog = (m_loader.content as MovieClip);
            m_centered = false;
            this.m_width = this.m_dialog.mc.width;
            this.m_height = this.m_dialog.mc.height;
            this.positionDialog();
            addEventListener(Event.ENTER_FRAME, this.updatePosition);
            this.onInitialize();
            addChild(this.m_dialog);
        }
        protected function onInitialize():void{
        }
        protected function updatePosition(_arg1:Event):void{
            if (this.m_resource == null){
                this.close();
            };
            if (((this.m_dialog.visible) && (Global.world.getTopGameMode().isDragging()))){
                this.positionDialog();
            };
        }
        override public function close():void{
            this.m_resource = null;
            removeEventListener(Event.ENTER_FRAME, this.updatePosition);
            super.close();
        }
        public function set xOffset(_arg1:int):void{
            this.m_xOffset = _arg1;
            this.positionDialog();
        }
        public function set yOffset(_arg1:int):void{
            this.m_yOffset = _arg1;
            this.positionDialog();
        }
        protected function positionDialog():void{
            if ((((this.m_resource == null)) || ((this.m_resource.getDisplayObject() == null)))){
                return;
            };
            var _local1:Vector3 = this.m_resource.getPosition();
            var _local2:Point = IsoMath.tilePosToPixelPos(_local1.x, _local1.y);
            _local2 = IsoMath.viewportToStage(_local2);
            _local2.x = (_local2.x - (this.m_width / 2));
            _local2.y = (_local2.y - (this.m_height + (this.m_resource.getDisplayObject().height / 2)));
            this.x = (_local2.x + this.m_xOffset);
            this.y = (_local2.y + this.m_yOffset);
        }

    }
}//package Display 
